import face_recognition
import cv2
import numpy as np

def get_encoding(input_image):
       
    # 返回图像中每个面的128维人脸编码
    # 图像中可能存在多张人脸，取下标为0的人脸编码，表示识别出来的最清晰的人脸
    image_face_encoding = face_recognition.face_encodings(input_image)[0]
    
    return image_face_encoding

# 将人脸编码的信息转换为字符串
def to_str(face_encoding):

    # 创建一个字符串，用来存放人脸编码后的字符信息
    str_face = ""

    for i in face_encoding:
        face_str = str(i)
        face_str = face_str[0:10]
        str_face = str_face + face_str
    return str_face

# 将人脸编码的信息从字符串转换为narray
def to_narray(str_face):
    
    # 存放字符串转换回来的人脸编码信息
    face_data = np.zeros(128)
    # 用来遍历字符串和face_data数组
    a = 0
    i = 0

    while a < 1280:
        qiepian_face = str_face[a:a+10]
        qiepian_face = float(qiepian_face)
        face_data[i] = qiepian_face
        a = a + 10
        i = i + 1

    return face_data


    